﻿using Engine;
using Game;
using Mekiasm.Interface;

namespace Mekiasm.ToolItems
{
    public class Cropnalyzer:ItemFlat
    {
        public static int Index;
        public Cropnalyzer() : base("作物/土壤分析仪", MekiasmInit.GetFlatTexture(MekiasmInit.R2, "cropnalyzer"))
        {
            Index = blockValue;
        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            if (raycast.HasValue)
            {
                int v = raycast.Value.Value;
                var block = BlocksManager.Blocks[Terrain.ExtractContents(v)];
                string n = block.GetDisplayName(componentMiner.m_subsystemTerrain, v);
                int data = Terrain.ExtractData(v);
                if (block is RyeBlock)
                {
                    bool a = RyeBlock.GetIsWild(data);
                    int b = RyeBlock.GetSize(data);
                    string c = a ? LanguageControl.Yes : LanguageControl.No;
                    DisplayMsg(componentMiner, $"目标:{n}\n野生:{c}\n当前生长周期:{b}\n最大生长周期:2");
                }
                else if (block is CottonBlock)
                {
                    bool a = CottonBlock.GetIsWild(data);
                    int b = CottonBlock.GetSize(data);
                    string c = a ? LanguageControl.Yes : LanguageControl.No;
                    DisplayMsg(componentMiner, $"目标:{n}\n野生:{c}\n当前生长周期:{b}\n最大生长周期:2");
                }
                else if (block is PumpkinBlock)
                {
                    bool a = BasePumpkinBlock.GetIsDead(data);
                    int b = BasePumpkinBlock.GetSize(data);
                    string c = a ? LanguageControl.Yes : LanguageControl.No;
                    DisplayMsg(componentMiner, $"目标:{n}\n死亡:{c}\n当前生长周期:{b}\n最大生长周期:7");
                }
                else if (block is SoilBlock)
                {
                    bool a = SoilBlock.GetHydration(data);
                    int b = SoilBlock.GetNitrogen(data);
                    string c = a ? LanguageControl.Yes : LanguageControl.No;
                    DisplayMsg(componentMiner, $"目标:{n}\n潮湿:{c}\n肥料值:{b}");
                }
                else if (block is MekBlock mek)
                {
                    var item = mek.GetItem(ref v);
                    if (item is GrowableSeed s)
                    {
                        int b = ILibrary.getExtraData(v);
                        DisplayMsg(componentMiner, $"目标:{n}\n当前周期:{b}\n最大周期:{s.MaxState}");
                    }
                }
                else
                {
                    DisplayMsg(componentMiner, "请对准作物或耕过的土壤使用");
                }
            }
            else
            {
                DisplayMsg(componentMiner, "请对准作物或耕过的土壤使用");
            }
            return true;
        }
    }
}
